package com.leetcode.q589;

import java.util.ArrayList;
import java.util.List;

/**
 * <p> description: desc</p>
 *
 * @author tanzc
 * @date 2022/3/30
 **/
public class NTreePreOrder {
    public List<Integer> preorder(Node root) {
        List<Integer> list = new ArrayList<>();
        order(root, list);
        return list;
    }

    public void order(Node node, List<Integer> list) {
        if (node == null) {
            return;
        }
        list.add(node.val);
        for (Node child : node.children) {
            order(child, list);
        }
    }
}

class Node {
    public int val;
    public List<Node> children;

    public Node() {
    }

    public Node(int _val) {
        val = _val;
    }

    public Node(int _val, List<Node> _children) {
        val = _val;
        children = _children;
    }
}
